#include "./stm32f1xx_it.h"
#include "./SYSTEM/sys/sys.h"
#include "./SYSTEM/usart/usart.h"
#include "./SYSTEM/delay/delay.h"
#include "./BSP/LED/led.h"
#include "./BSP/OLED/OLED.h"
#include "./BSP/ESP8266/ESP8266.h"
#include "./BSP/MPU6050/MPU6050.h"
#include "./BSP/MPU6050/inv_mpu.h"

uint8_t ret;
uint8_t ID;
float Pitch,Roll,Yaw;								//俯仰角默认跟中值一样，翻滚角，偏航角
int16_t AX,AY,AZ,GX,GY,GZ;							//加速度，陀螺仪角速度

int main(void)
{
    HAL_Init();                         /* HAL库初始化 */
    sys_stm32_clock_init(RCC_PLL_MUL9); /* 设置时钟, 72Mhz */
    delay_init(72);                     /* 延时初始化 */
    led_init();                         /* 初始化LED */
    OLED_Init();
    usart1_init(115200);
    //usart3_init(115200);
    MPU6050_Init();
    ID = MPU6050_GetID();

    //OLED_Printf(0, 1, OLED_8X16, "OLED");
    OLED_Printf(0, 0,OLED_8X16, "ID: %x", ID);
    OLED_Update();

    //UART_printf(&g_uart3_handle,"\r\n我相信 \r\n");

    while (1)
    {
        MPU_Get_Gyroscope(&GX,&GY,&GZ);
        MPU_Get_Accelerometer(&AX,&AY,&AZ);
        OLED_Printf(0,16,OLED_8X16,"%.2f",Pitch );
        OLED_Printf(0,32,OLED_8X16,"%.2f",Roll);
        OLED_Printf(0,48,OLED_8X16,"%.2f",Yaw);
        OLED_Update();
        UART_printf(&g_uart1_handle,"%d,%d,%d,%d,%d,%d\r\n",AX,AY,AZ,GX,GY,GZ);
    }
}
/*
    ESP8266_exit_unvarnished();
    ESP8266_at_test();
    ESP8266_set_mode(1);
    ESP8266_sw_reset();
    ESP8266_join_ap("TP-LINK_021F","zhao15234707792");
    ESP8266_send_at_cmd("AT+CIPMUX=0","OK",20);
    ESP8266_connect_tcp_server("192.168.1.101","8000");
    ESP8266_enter_unvarnished();
*/
